package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

@Getter
public enum ChildClueRuleEnum {

    /**
     * 所有线索统一设置
     */
    CLUE_ALL(0, "enum.childClueRule.name.clue_all"),
    /**
     * 根据线索状态设置
     */
    CLUE_STATUS(1, "enum.childClueRule.name.clue_status"),
    /**
     * 根据线索标签设置
     */
    CLUE_LABEL(2, "enum.childClueRule.name.clue_label"),
    /**
     * 未知规则,当异常时用于返回
     */
    UNKNOWN(404, "enum.childClueRule.name.unknown");


    /**
     * 枚举值 --
     */
    private final int code;

    /**
     * 枚举信息--中文名称
     */
    private final String name;


    /**
     * 构造一个<code>SubModuleEnum</code>枚举对象
     *
     * @param code  枚举值
     * @param name  枚举名
     */
    ChildClueRuleEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * @return Returns the code.
     */
    public int getCode() {
        return code;
    }

    /**
     * @return Returns the name.
     */
    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code 枚举值
     *
     * @return PublicCustomerRuleEnum
     */
    public static ChildClueRuleEnum getByCode(Integer code) {
        for (ChildClueRuleEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<PublicCustomerRuleEnum>
     */
    public static List<ChildClueRuleEnum> getAllEnum() {
        List<ChildClueRuleEnum> list = new ArrayList<>();
        for (ChildClueRuleEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }
}
